﻿using System.Collections.Generic;

namespace base31.Hub.Helpers
{
    public class Constants
    {
        // How many subscribers to contact at a time when delivering events.
        public const int EVENT_SUBSCRIBER_CHUNK_SIZE = 50;

        // Maximum number of times to attempt a subscription retry.
        public const int MAX_SUBSCRIPTION_CONFIRM_FAILURES = 4;

        // Period to use for exponential backoff on subscription confirm retries.
        public const int SUBSCRIPTION_RETRY_PERIOD = 30;// seconds

        // Maximum number of times to attempt to pull a feed.
        public const int MAX_FEED_PULL_FAILURES = 4;

        // Period to use for exponential backoff on feed pulling.
        public const int FEED_PULL_RETRY_PERIOD = 30;// seconds

        // Maximum number of times to attempt to deliver a feed event.
        public const int MAX_DELIVERY_FAILURES = 4;

        // Period to use for exponential backoff on feed event delivery.
        public const int DELIVERY_RETRY_PERIOD = 30; // seconds

        // Period at which feed IDs should be refreshed.
        public const int FEED_IDENTITY_UPDATE_PERIOD = (20 * 24 * 60 * 60); // 20 days

        // Number of polling feeds to fetch from the Datastore at a time.
        public const int BOOSTRAP_FEED_CHUNK_SIZE = 50;

        // Maximum age in seconds of a failed EventToDeliver before it is cleaned up.
        public const int EVENT_CLEANUP_MAX_AGE_SECONDS = (10 * 24 * 60 * 60);  // 10 days

        // How many completely failed EventToDeliver instances to clean up at a time.
        public const int EVENT_CLEANUP_CHUNK_SIZE = 50;

        // How many old Subscription instances to clean up at a time.
        public const int SUBSCRIPTION_CLEANUP_CHUNK_SIZE = 100;

        // How far before expiration to refresh subscriptions.
        public const int SUBSCRIPTION_CHECK_BUFFER_SECONDS = (24 * 60 * 60);  // 24 hours

        // How many mapper shards to use for reconfirming subscriptions.
        public const int SUBSCRIPTION_RECONFIRM_SHARD_COUNT = 4;

        // How often to poll feeds.
        public const int POLLING_BOOTSTRAP_PERIOD = 10800;  // in seconds; 3 hours

        // Default expiration time of a lease.
        public const int DEFAULT_LEASE_SECONDS = (5 * 24 * 60 * 60); // 5 days

        // Maximum expiration time of a lease.
        public const int MAX_LEASE_SECONDS = (10 * 24 * 60 * 60);  // 10 days

        // Maximum number of redirects to follow when feed fetching.
        public const int MAX_REDIRECTS = 7;

        // Maximum time to wait for fetching a feed in seconds.
        public const int MAX_FETCH_SECONDS = 10;

        // Number of times to try to split FeedEntryRecord, EventToDeliver, and
        // FeedRecord entities when putting them and their size is too large.
        public const int PUT_SPLITTING_ATTEMPTS = 10;

        // Maximum number of FeedEntryRecord entries to look up in parallel.
        public const int MAX_FEED_ENTRY_RECORD_LOOKUPS = 500;

        // Maximum number of FeedEntryRecord entries to save at the same time when
        // a new EventToDeliver is being written.
        public const int MAX_FEED_RECORD_SAVES = 100;

        // Maximum number of new FeedEntryRecords to process and insert at a time. Any
        // remaining will be split into another EventToDeliver instance.
        public const int MAX_NEW_FEED_ENTRY_RECORDS = 200;



        public const string ATOM = "atom";
        public const string RSS = "rss";
        public const string ARBITRARY = "arbitrary";

        public static List<char> ValidChars = new List<char>
        {
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
        };

        public static List<int> ValidPorts = new List<int>
        {
            80, 443, 4443, 8080, 8081, 8082, 8083, 8084, 8085,
            8086, 8087, 8088, 8089, 8188, 8444, 8990
        };

        public const string EVENT_QUEUE = "event-delivery";

        public const string EVENT_RETRIES_QUEUE = "event-delivery-retries";

        public const string FEED_QUEUE = "feed-pulls";

        public const string FEED_RETRIES_QUEUE = "feed-pulls-retries";

        public const string POLLING_QUEUE = "polling";

        public const string SUBSCRIPTION_QUEUE = "subscriptions";

        public const string MAPPINGS_QUEUE = "mappings";
    }
}
